<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>
  <body>
    <div id="demo" index="1" class="nav"></div>
    <script>
      var div = document.querySelector('div');
      console.log(div.id);                     // 结果为：demo
      console.log(div.getAttribute('id'));     // 结果为：demo
      console.log(div.getAttribute('index'));  // 结果为：1
    </script>
  </body>
</html>